How to count children from different lists? [jQuery]

Posted by Filip Breckx on Stack Overflow See other posts from Stack Overflow or by Filip Breckx
Published on 2010-05-21T07:49:15Z Indexed on 2010/05/21 7:50 UTC
Read the original article Hit count: 224

Filed under:

Hi,

I'm trying to count the number of child elements a certain category has.

This is the situation:

<ul id="select_cat">
  <li id="_1">Category 1 (<span>#</span>)</li>
  <li id="_2">Category 2 (<span>#</span>)</li>
</ul>

<ul id="cat_1>
  <li>Link 1</li>
  <li>Link 2</li>
  <li>Link 3</li>
</ul>

<ul id="cat_2">
  <li>Link 1</li>
  <li>Link 2</li>
</ul> 

So I want to count the number of children a category has. In this example the first cardinal sign should be 3, and the second should be 2.

How can I do this, using jQuery.

Check an example (not jQuery)

Thanks!

© Stack Overflow or respective owner

Related posts about jQuery